//package com.ruoyi.zjext.config;
//
//import com.jcraft.jsch.JSch;
//import com.jcraft.jsch.Session;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.boot.web.servlet.ServletContextInitializer;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.PostConstruct;
//import javax.servlet.ServletContext;
//import javax.servlet.ServletException;
//
//
//@Component
//public class SshConfiguration implements ServletContextInitializer {
//    protected final Logger log = LoggerFactory.getLogger(this.getClass());
//    @Value("${ssh.forward.enabled}")
//    private boolean enabled;
//    @Value("${ssh.forward.username}")
//    private String username;
//    @Value("${ssh.forward.host}")
//    private String host;
//    @Value("${ssh.forward.port}")
//    private int port;
//    @Value("${ssh.forward.password}")
//    private String password;
//
//    @PostConstruct
//    private void init() {
//        try {
//            //如果配置文件包含ssh.forward.enabled属性，则使用ssh转发
//            if(enabled){
//                log.info("try ssh forward is open.");
//                Session session = new JSch().getSession(username, host, port);
//                session.setConfig("StrictHostKeyChecking", "no");
//                session.setPassword(password);
//                session.connect();
//                session.setPortForwardingL(3306, "127.0.0.1", 3306);
//                session.setPortForwardingL(6379, "127.0.0.1", 6379);
//                log.info("ssh forward opened.");
//            }else{
//                log.info("ssh forward is closed.");
//            }
//        } catch (Exception e) {
//            log.error("ssh Exception failed.", e);
//        }
//    }
//
//    @Override
//    public void onStartup(ServletContext servletContext) throws ServletException {
//    }
//}